#include <iostream>
#include "comm.hpp"
#include "log.hpp"

using namespace std;

int main()
{
    // 创建信道
    Init myfifo;
    Log log;
    log.Enable(Classfile);
    // 打开文件
    int rfd = open(FIFO_FILE, O_RDONLY);
    if (rfd < 0)
    {
        log(Fatal, "%s %d", strerror(errno), errno);
        exit(FILE_OPEN_ERR);
    }
    cout << "server open file done" << endl;
    // 进行
    while (true)
    {
        char buffer[1023] = {0};
        int red = read(rfd, buffer, sizeof(buffer));
        if (red > 0)
        {
            buffer[red] = 0;
            cout << "client say@: " << buffer << endl;
        }
        if (red == 0)
        {
            log(Debug, "client quit ,read me too !!! %s %d", strerror(errno), errno);
            break;
        }
    }
    // 关闭文件
    close(rfd);
    return 0;
}